package pantomime.recognize;
import java.util.ArrayList;
import java.lang.*;

import pantomime.gestures.*;
import pantomime.hardware.*;
import processing.core.*;

public class RecognitionEngine {

	/**
	 * 
	 * @param oDefinitions
	 * @param oGlove
	 * @return rtn[] where rtn[0] = gesture ID, rtn[1] = confidence percentage
	 */
	public static int[] recognize(GestureCollection oDefinitions, Glove oGlove){
		oGlove = normalizeGlove(oGlove);
		System.out.println(oGlove.oFlexSensor.toString());
		System.out.println(oGlove.oIMU.toString());
		
		int largestPercent = 0;
		int rtnPercent = 0;
		int[] rtn = {-1,-1};
				
		for(int i = 0; i < oDefinitions.size(); i++){
			StaticGesture oDef = (StaticGesture) oDefinitions.getGesture(i);

			rtnPercent = (int) Math.round(oDef.compareToGlove(oGlove)); 
			
			if(rtnPercent > largestPercent){	//constantly update the largest percentage match
				largestPercent = rtnPercent;
				rtn[0] = oDef.getID();
				rtn[1] = largestPercent;
			}
			if(largestPercent == 100){
				return rtn;
			}						
		}
		return rtn;
	}
	
	public static int recognize(GestureCollection oDefinitions, int sensorValues[]){
		
		for(int i = 0; i < oDefinitions.size(); i++){
			
		}
		
		return -1;
	}
	
	
	private static Glove normalizeGlove(Glove oGlove){
		
		oGlove.oIMU.normalizeIMU();
		oGlove.oFlexSensor.normalizeFlex();
		
		return oGlove;
	}

	
	private static String getIMUOrientation(IMU oIMU){
		
	//	if(oIMU.)
		return "";
	}

}